package com.cn.mapper;

import com.cn.pojo.User;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

public interface UserMapper {
    @Select("select * from user where id = #{id}")
    @Results(id = "userResultMap",value = {
            @Result(property = "id",column = "id",id = true),
            @Result(property = "username",column = "username"),
            @Result(property = "password",column = "password"),
            @Result(property = "gender",column = "gender")
    })
    User selectById(int id);

    //在你的 UserMapper 接口中，如果希望 getUserById 方法使用 userResultMap 映射结果，可以通过 @ResultMap 注解来引用已经定义好的 userResultMap。这允许你复用 selectById 方法中定义的 @Results 注解配置，避免重复编写结果映射
    @Select("SELECT id, username, password,gender FROM user WHERE id = #{id}")
    @ResultMap("userResultMap")  // 引用已经定义的 userResultMap
    User getUserById(int id);


    // 方式二：使用UserMapper.xml中定义的Mapper
    @Select("SELECT id, username, password,gender FROM user WHERE id = #{id}")
    @ResultMap("userResultMap1")  // 引用已经定义的 userResultMap
    User getUserWithId(int id);


}
